'''
Created on Jan 5, 2014

@author: Leon
'''

import maya.cmds as mc
from cgm.lib import curves

def setColor(ctl, colorId):
    '''
    ctl - ctl transform (will find shape)
    colorTable - {'token':colorId}
    '''
    ctlShapes = ctl.getChildren(type='shape')
    for ctlShape in ctlShapes:
        ctlShape.overrideEnabled.set(True)
        ctlShape.overrideColor.set(colorId)

def createControl(controlType=None, color=0):
    '''
    controlType (string) - eyeball, uppereyelid, lowereyelid
    return name of control (string)
    '''
    
    createdCurves = []
    
    if controlType == 'eyeball':
        # eyeball control
        createdCurves.append(mc.curve( d = 3,p = [[-2.0, 0.0, 0.0], [-1.7410218346353992, 0.2589781653646009, 0.0], [-1.0960546349793177, 0.6343203989838185, 0.0], [-2.446163389034639e-16, 0.8074550147753012, 0.0], [1.0960546349793174, 0.6343203989838179, 0.0], [1.7410218346353985, 0.2589781653646016, 0.0], [2.0, 0.0, 0.0]],k = (0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 4.0)))
        createdCurves.append(mc.curve( d = 3,p = [[4.286263797015736e-17, 0.7, 0.0], [-0.17811519070418735, 0.7, 0.0], [-0.5489785167141249, 0.5494107756462852, 0.0], [-0.7747646195700771, 0.003382897653852665, 0.0], [-0.5519230240326511, -0.54461646726576, 0.0], [-0.0067656301510380795, -0.7752644262815899, 0.0], [0.5423340955436322, -0.5541659044773989, 0.0], [0.7747056588706507, -0.010139124611810102, 0.0], [0.5584834447845943, 0.5397461015249914, 0.0], [0.1903047474040215, 0.69678484790865, 0.0], [0.0122166845060987, 0.6998933866094739, 0.0]],k = (0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 8.0, 8.0)))
        createdCurves.append(mc.curve( d = 3,p = [[-2.0, 0.0, 0.0], [-1.7410218346353992, -0.2589781653646009, 0.0], [-1.0960546349793177, -0.6343203989838185, 0.0], [-2.446163389034639e-16, -0.8074550147753012, 0.0], [1.0960546349793174, -0.6343203989838179, 0.0], [1.7410218346353985, -0.2589781653646016, 0.0], [2.0, 0.0, 0.0]],k = (0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 4.0)))

    elif controlType == 'uppereyelid':
        # uppereyelid control
        createdCurves.append(mc.curve( d = 3,p = [[-2.0, 0.0, 0.0], [-1.7410218346353992, 0.2589781653646009, 0.0], [-1.0960546349793177, 0.6343203989838185, 0.0], [-2.446163389034639e-16, 0.8074550147753012, 0.0], [1.0960546349793174, 0.6343203989838179, 0.0], [1.7410218346353985, 0.2589781653646016, 0.0], [2.0, 0.0, 0.0]],k = (0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 4.0)))
        createdCurves.append(mc.curve( d = 3,p = [[-2.0, 0.0, 0.0], [-1.6741765841276626, 0.0826315157302451, 0.0], [-1.0063776917734268, 0.16297797352985877, 0.0], [1.2342828582118104e-15, 0.20455714681939524, 0.0], [1.0063776917734248, 0.16297797352985888, 0.0], [1.6741765841276648, 0.08263151573024477, 0.0], [2.0, 0.0, 0.0]],k = (0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 4.0)))
    
    elif controlType == 'lowereyelid':
        # lowereyelid control
        createdCurves.append(mc.curve( d = 3,p = [[-2.0, 0.0, 0.0], [-1.7410218346353992, -0.2589781653646009, 0.0], [-1.0960546349793177, -0.6343203989838185, 0.0], [-2.446163389034639e-16, -0.8074550147753012, 0.0], [1.0960546349793174, -0.6343203989838179, 0.0], [1.7410218346353985, -0.2589781653646016, 0.0], [2.0, 0.0, 0.0]],k = (0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 4.0)))
        createdCurves.append(mc.curve( d = 3,p = [[-2.0, 0.0, 0.0], [-1.6741765841276626, -0.0826315157302451, 0.0], [-1.0063776917734268, -0.16297797352985877, 0.0], [1.2342828582118104e-15, -0.20455714681939524, 0.0], [1.0063776917734248, -0.16297797352985888, 0.0], [1.6741765841276648, -0.08263151573024477, 0.0], [2.0, 0.0, 0.0]],k = (0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 4.0)))
        
    else:
        pass
    
    crv = curves.combineCurves(createdCurves)
    curves.setColorByIndex(crv, color)
    
    return crv